﻿@model Think9.Models.TbIndexEntity
@{ ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<form class="layui-form" lay-filter="formEdit">
    <input style="display:none" id="tbid" value="@ViewBag.tbid">
    <input style="display:none" id="BSelMuch" value="@Model.BSelMuch">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">

            <label class="layui-form-label">指标名称</label>
            <div class="layui-input-block">
                <input type="text" name="IndexName" id="IndexName" placeholder="指标名称" autocomplete="off" class="layui-input" lay-verify="required" readonly="readonly">
            </div>
        </div>
        <div class="layui-col-md6">

            <label class="layui-form-label">指标编码</label>
            <div class="layui-input-block">
                <input type="text" name="IndexId" id="IndexId" placeholder="指标编码" autocomplete="off" class="layui-input" lay-verify="required" readonly="readonly">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">

            <label class="layui-form-label">指标类型</label>
            <div class="layui-input-block">
                <input type="text" name="DataType" id="DataType" placeholder="指标类型" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
        <div class="layui-col-md6">

            <label class="layui-form-label">列表排序</label>
            <div class="layui-input-block">
                <input type="text" name="IndexOrderNo" id="IndexOrderNo" placeholder="请输入1-999的整数 录入表内排序号须唯一" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <label class="layui-form-label">列表表头</label>
            <div class="layui-input-block">
                <input type="text" name="ListHeadName" id="ListHeadName" placeholder="列表名称(表头)" autocomplete="off" class="layui-input" maxlength="30">
                <span style="position: absolute;bottom: 0px; right: 5px;">
                    <i class="fa fa-question-circle" id="info01"></i>
                </span>
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">列表列宽</label>
            <div class="layui-input-block">
                <input type="text" name="ColumnWith" id="ColumnWith" placeholder="列表列宽 (5至1000之间)" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <label class="layui-form-label">默认值</label>
            <div class="layui-input-block">
                <input type="text" name="DefaultV" id="DefaultV" placeholder="默认值" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md6">

            <label class="layui-form-label">计算式</label>
            <div class="layui-input-block">
                <input type="text" name="Auto02" id="Auto02" placeholder="自动计算式" autocomplete="off" class="layui-input">
                <span style="position: absolute;bottom: -2px; right: 5px;">
                    <i class="fa fa-edit" id="selAuto02"></i>
                </span>
            </div>
        </div>
    </div>

    <fieldset class="table-fieldset">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="BEmpty" value="1">
                    <input type="checkbox" name="BEmpty" id="BEmpty" lay-skin="primary" title="必填" value="2" lay-filter="BEmpty"> <span style="position: absolute;bottom: 0px; right: 120px;">
                        <i class="fa fa-question-circle" id="info02"></i>
                    </span>
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BUnique" value="2">
                    <input type="checkbox" name="BUnique" id="BUnique" lay-skin="primary" title="唯一" value="1" lay-filter="BUnique">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BPK" value="2">
                    <input type="checkbox" name="BPK" id="BPK" lay-skin="primary" title="主键" value="1" lay-filter="BPK">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BOrder" value="2">
                    <input type="checkbox" name="BOrder" id="BOrder" lay-skin="primary" title="排序" value="1" lay-filter="BOrder">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BSearch" value="2">
                    <input type="checkbox" name="BSearch" id="BSearch" lay-skin="primary" title="查询条件" value="1" lay-filter="BSearch">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BSearch2" value="2">
                    <input type="checkbox" name="BSearch2" id="BSearch2" lay-skin="primary" title="快速查询" value="1" lay-filter="BSearch2">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="BColumnShow2" value="2">
                    <input type="checkbox" name="BColumnShow2" id="BColumnShow2" lay-skin="primary" title="列表显示" value="1" lay-filter="BColumnShow2">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BColumnShow" value="2">
                    <input type="checkbox" name="BColumnShow" id="BColumnShow" lay-skin="primary" title="查询列表显示" value="1" lay-filter="BColumnShow">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="Code01" value="2">
                    <input type="checkbox" name="Code01" id="Code01" lay-skin="primary" title="可扫码" value="1" lay-filter="Code01">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="ListStat" value="2">
                    <input type="checkbox" name="ListStat" id="ListStat" lay-skin="primary" title="统计求和(数值类型)" value="1" lay-filter="ListStat">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BTime" value="2">
                    <input type="checkbox" name="BTime" id="BTime" lay-skin="primary" title="日期+时间(日期类型)" value="1" lay-filter="BTime">
                </div>
                <div class="layui-input-inline">
                    <input type="hidden" name="BShow" value="1">
                    <input type="checkbox" name="BShow" id="BShow" lay-skin="primary" title="隐藏指标(录入页面不显示)" value="2" lay-filter="BShow">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="hidden" name="isHtmlTag" value="2">
                    <input type="checkbox" name="isHtmlTag" id="isHtmlTag" lay-skin="primary" title="显示HtmlTag" value="1" lay-filter="BTime">
                </div>
                <div class="layui-inline">
                    <select lay-verify="required" name="BLock" id="BLock">
                        <option value="2">不锁定</option>
                        <option value="1">锁定(不可编辑)</option>
                        <option value="9">编辑时锁定</option>
                    </select>
                </div>
            </div>
        </div>
    </fieldset><br />
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <label class="layui-form-label">控件类型</label>
            <div class="layui-input-block">
                @Html.DropDownList("ControlType", (IEnumerable<SelectListItem>)ViewBag.ControlType, "==请选择控件类型==", new Dictionary<string, object> { { "lay-verify", "required" } })
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">适用规则</label>
            <div class="layui-input-block">
                @Html.DropDownList("ControlBy3", (IEnumerable<SelectListItem>)ViewBag.ValidateList, "==请选择==", new Dictionary<string, object> { })
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6">
            <label class="layui-form-label">数据规范</label>
            <div class="layui-input-block">
                <input type="text" name="RuleName" id="RuleName" placeholder="数据规范" class="layui-input" readonly="readonly">
                <span style="position: absolute;bottom: 20px; right: 5px;">
                    <i class="fa fa-edit" id="selRule"></i>
                </span>
                <span style="color:#a29c9c;font-size: 12px;">弹出的编辑页面中选择可多选，可设置为可多选的弹出页面</span>
            </div>
        </div>
        <div class="layui-col-md6">
            <label class="layui-form-label">提示说明</label>
            <div class="layui-input-block">
                <input type="text" name="ControlBy1" id="ControlBy1" placeholder="提示说明" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="edit">编辑</button>
        </div>
    </div>
</form>
<script>
    layui.use(["form", "exLayer", "exUtils", "layer"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let layer = layui.layer;

        let $ = layui.$;

        getVal();
        form.render(); //初始化表单，要加上，不然刷新部分组件可能会不加载

        $("#info01").click(function () {
            layer.tips('Hi，我是一个小提示', this, { tips: 1 });
        });

        $("#selRule").click(function () {
            exLayer.open("录入表指标数据规范选择", "/SysTable/TbSetUp/SelectRuleList?tbid=" + $("#tbid").val() + "&indexid=" + $('#IndexId').val() + "&ismuch=" + $('#BSelMuch').val(), '100%', '100%', '0px', '0px', null, null);
        });

        $("#selAuto02").click(function () {
            exLayer.open("计算式", "/SysTable/TbSetUp/PUFormula?tbid=" + $("#tbid").val() + "&fid=main"  + "&some=" + $('#Auto02').val(), '100%', '100%', '0px', '0px', null, null);
        });

        //给表单赋值
        form.val("formEdit", {
            "IndexId": "@Model.IndexId",
            "IndexName": "@Model.IndexName",
            "DataType": "@Model.DataType",
            "IndexOrderNo": "@Model.IndexOrderNo",
            "ListHeadName": "@Model.ListHeadName",
            "ColumnWith": "@Model.ColumnWith",
            "DefaultV": "@Model.DefaultV",
            "Auto02": "@Model.Auto02",
            "ControlType": "@Model.ControlType",
            "ControlBy3": "@Model.ControlBy3",
            "RuleName": "@Model.RuleName",
             "BLock": "@Model.BLock",
            "ControlBy1": "@Html.Raw(Model.ControlBy1)"
        });

        form.on("submit(edit)", function (data) {
            exUtils.ajax("/SysTable/TbSetUp/UpTbIndexByTbIndexID?tbid=" + $("#tbid").val() + "&indexid=" + $('#IndexId').val(), "post", data.field, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    parent.location.reload(); // 父页面刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        function getVal() {
             if (@Model.BShow == "2") {
                 $('#BShow').attr("checked", true);
             }
            else {
                 $("#BShow").removeAttr("checked");
             }

            if (@Model.BPK == "1") {
                $('#BPK').attr("checked", true);
            }
            else {
                $("#BPK").removeAttr("checked");
            }

            if (@Model.BUnique == "1") {
                $('#BUnique').attr("checked", true);
            }
            else {
                $("#BUnique").removeAttr("checked");
            }

            if (@Model.BEmpty == "2") {
                $('#BEmpty').attr("checked", true);
            }
            else {
                $("#BEmpty").removeAttr("checked");
            }

            if (@Model.BOrder == "1") {
                $('#BOrder').attr("checked", true);
            }
            else {
                $("#BOrder").removeAttr("checked");
            }

            if (@Model.BSearch == "1") {
                $('#BSearch').attr("checked", true);
            }
            else {
                $("#BSearch").removeAttr("checked");
            }

            if (@Model.BSearch2 == "1") {
                $('#BSearch2').attr("checked", true);
            }
            else {
                $("#BSearch2").removeAttr("checked");
            }

            if (@Model.BColumnShow == "1") {
                $('#BColumnShow').attr("checked", true);
            }
            else {
                $("#BColumnShow").removeAttr("checked");
            }

            if (@Model.BColumnShow2 == "1") {
                $('#BColumnShow2').attr("checked", true);
            }
            else {
                $("#BColumnShow2").removeAttr("checked");
            }

            if (@Model.Code01 == "1") {
                $('#Code01').attr("checked", true);
            }
            else {
                $("#Code01").removeAttr("checked");
            }

            if (@Model.ListStat == "1") {
                $('#ListStat').attr("checked", true);
            }
            else {
                $("#ListStat").removeAttr("checked");
            }

            if (@Model.BTime == "1") {
                $('#BTime').attr("checked", true);
            }
            else {
                $("#BTime").removeAttr("checked");
            }

            if (@Model.isHtmlTag == "1") {
                $('#isHtmlTag').attr("checked", true);
            }
            else {
                $("#isHtmlTag").removeAttr("checked");
            }
        }

    });
</script>